package com.tiantianfresh.model.dao;

import com.tiantianfresh.model.pojo.Permission;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @author FANGAO
 * @date 2021/11/15 - 下午 14:06
 */
public interface PermissionMapper extends Mapper<Permission> {
    /**
     * 拿到顶点
     * @return
     */
    @Select("select * from t_permission where pid is null")
    Permission queryRoot();

    @Select("select * from t_permission where pid = #{id}")
    List<Permission> queryChidPermissions(@Param("id") Integer id);

    @Select("select * from t_permission")
    List<Permission> queryAll();

    int insert(Permission permission);

    @Select("select * from t_permission where id = #{id}")
    Permission queryById(@Param("id") Integer id);

    int update(Permission permission);

    @Delete("delete from t_permission where id = #{id}")
    int detele(@Param("id")Integer id);

    @Select("select permissionid from t_role_permission where roleid =#{id}")
    List<Integer> queryRolePermissions(Integer id);

    /**
     * 根据用户id查询他的许可
     * @param id
     * @return
     */
    List<Permission> queryUserPermission(Integer id);
}
